package com.ait.cms.service.impl;

import com.ait.cms.entity.EduComment;
import com.ait.cms.mapper.EduCommentMapper;
import com.ait.cms.service.EduCommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-07-06
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public Map<String, Object> getpageComment(Page<EduComment> page, String id) {
        QueryWrapper<EduComment> wrapper = new QueryWrapper<>();
        wrapper.eq("course_id",id);
        this.page(page,wrapper);

        HashMap<String, Object> map = new HashMap<>();

        List<EduComment> records = page.getRecords();

        long total = page.getTotal();
        long current = page.getCurrent();
        long size = page.getSize();
        long pages = page.getPages();

        boolean hasNext = page.hasNext();
        boolean hasPrevious = page.hasPrevious();


        map.put("items",records);
        map.put("total",total);
        map.put("current",current);
        map.put("size",size);
        map.put("pages",pages);

        map.put("hasNext",hasNext);
        map.put("hasPrevious",hasPrevious);
        return map;
    }
}
